# Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
#
# Licensed under the BSD 3-Clause License (the "License"); you may not use this
# file except in compliance with the License. You may obtain a copy of the
# License at
#
# https://opensource.org/licenses/BSD-3-Clause
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

exports_files([
    "event_loop_notifier.cc",
    "event_loop_notifier.h",
    "watchdog.cc",
    "watchdog.h",
])

cc_library(
    name = "eintr_safe",
    srcs = ["eintr_safe.cc"],
    hdrs = ["eintr_safe.h"],
    visibility = ["//flare:__subpackages__"],
    deps = [
        "//flare/base:likely",
        "//flare/fiber:alternatives",
    ],
)

cc_library(
    name = "timed_call",
    srcs = ["timed_call.cc"],
    hdrs = ["timed_call.h"],
    visibility = ["//flare:__subpackages__"],
    deps = [
        "//flare/base:deferred",
        "//flare/base:logging",
        "//flare/base:tsc",
        "@com_github_gflags_gflags//:gflags",
    ],
)

cc_library(
    name = "writing_buffer_list",
    srcs = ["writing_buffer_list.cc"],
    hdrs = ["writing_buffer_list.h"],
    visibility = ["//flare:__subpackages__"],
    deps = [
        ":eintr_safe",
        "//flare/base:align",
        "//flare/base:buffer",
        "//flare/base:chrono",
        "//flare/base:likely",
        "//flare/base:object_pool",
        "//flare/base/internal:annotation",
        "//flare/base/internal:test_prod",
        "//flare/io/util:stream_io",
    ],
)

cc_test(
    name = "writing_buffer_list_test",
    srcs = ["writing_buffer_list_test.cc"],
    deps = [
        ":writing_buffer_list",
        "//flare/base/thread:latch",
        "//flare/io/util:socket",
        "//flare/testing:main",
    ],
)

cc_library(
    name = "writing_datagram_list",
    srcs = ["writing_datagram_list.cc"],
    hdrs = ["writing_datagram_list.h"],
    visibility = ["//flare:__subpackages__"],
    deps = [
        ":eintr_safe",
        "//flare/base:buffer",
        "//flare/base/internal:annotation",
        "//flare/base/net:endpoint",
    ],
)

cc_test(
    name = "writing_datagram_list_test",
    srcs = ["writing_datagram_list_test.cc"],
    deps = [
        ":writing_datagram_list",
        "//flare/fiber:alternatives",
        "//flare/io/util:socket",
        "//flare/testing:endpoint",
        "//flare/testing:main",
    ],
)

cc_library(
    name = "read_at_most",
    srcs = ["read_at_most.cc"],
    hdrs = ["read_at_most.h"],
    visibility = ["//flare:__subpackages__"],
    deps = [
        "//flare/base:buffer",
        "//flare/base:logging",
        "//flare/base:object_pool",
        "//flare/base/internal:annotation",
        "//flare/fiber:alternatives",
        "//flare/io/util:stream_io",
    ],
)

cc_test(
    name = "read_at_most_test",
    srcs = ["read_at_most_test.cc"],
    deps = [
        ":read_at_most",
        "//flare/base:random",
        "//flare/io/util:socket",
        "//flare/testing:endpoint",
        "//flare/testing:main",
    ],
)

# `watchdog` is compiled with `io/event_loop.cc`. No `cc_library` here.

cc_test(
    name = "watchdog_test",
    srcs = ["watchdog_test.cc"],
    deps = [
        "//flare/io:io_basic",
        "//flare/testing:main",
        "@com_github_gflags_gflags//:gflags",
    ],
)
